import { EChartsOption } from 'echarts'
import { EChartsProps } from 'type'
import { LineTransformedProps } from 'type/line'

function echartOptions(transformProps: LineTransformedProps): EChartsProps {
  const { width, height, key = 'key', value = 'value', formData } = transformProps
  const echartOptions: EChartsOption = {
    xAxis: {
      type: 'category',
      show: false,
      boundaryGap: false,
      data: formData.map((item) => item[key]),
    },
    yAxis: {
      type: 'value',
      show: false,
    },
    grid: {
      left: 0,
      right: 0,
      top: 0,
      bottom: 0,
      width: '100%',
      containLabel: false,
    },
    series: [
      {
        type: 'line',
        itemStyle: {
          opacity: 0,
        },
        lineStyle: {
          opacity: 0,
        },
        smooth: true,
        data: formData.map((item) => item[value]),
        areaStyle: {
          color: '#a64ca6',
        },
      },
    ],
  }
  return {
    width,
    height,
    echartOptions,
  }
}

export default echartOptions